<?php
/**
 * Created by PhpStorm.
 * User: qylxz
 * Date: 2018/10/9
 * Time: 上午10:38
 */

namespace app\admin\controller;


use app\admin\model\ApplyopenModel;
use cmf\controller\AdminBaseController;

class ApplyopenController extends AdminBaseController
{
    /***
     * 1. 获取所有未审核
     * 2. 请求方式: POST
     * 3. 必须参数: type = 1表示未审核，type = 2表示已审核，type = 3表示未通过
     */
    public function getAllUnVerify(){
        $model = new ApplyopenModel();
        $list = $model->getUnVerifyList();
        $this->assign('type', 1);
        $this->assign('list', $list);
        $params = $this->request->param();
        $list->appends($params);
        $where['status'] = 0;
        $count = $model->getCount($where);
        $this->assign('count', $count);
        $this->assign('page', $list->render());
        return $this->fetch('unverify');
    }

    /**
     * 1. 查看信息
     * 2. 请求方式: GET
     * 3. 必须参数: id
     */
    public function lookUp(){
        $data = input('get.');
        filter_var($data,FILTER_SANITIZE_NUMBER_INT);
        $uid = $data['id'];
        $type = $data['type'];
        $model = new ApplyopenModel();
        $info = $model->getInfo($uid);
        $this->assign('type', $type);
        $this->assign('info', $info);
        return $this->fetch('detail');
    }

    /**
     * 1. 删除某一信息
     * 2. 请求方式: GET
     * 3. 必须参数: id
     */
    public function deleteInfo(){
        $uid = input('get.id');
        $deal =filter_var($uid,FILTER_SANITIZE_NUMBER_INT);
        $model = new ApplyopenModel();
        $isSuccess = $model->getDelete($deal);
        if ($isSuccess) {
            $this->success('删除成功');
        } else {
            $this->error('删除失败');
        }

    }

    /**
     * 1. 未审核或未通过状态改为已审核
     * 2. 请求方式: GET
     * 3. 所需参数: id
     */
    public function changeStatus(){
        $data = input('get.');
        filter_var($data,FILTER_SANITIZE_NUMBER_INT);
        $uid = $data['id'];
        $model = new ApplyopenModel();
        $isSuccess = $model->getChange($uid);
        if ($isSuccess)
        {
            if ($data['type'] == 0){
                $this->redirect('getAllUnVerify');
            }else{
                $this->redirect('getAllUnPassVerify');
            }

        }else{
            $this->error('通过失败');
        }
    }

    /***
     * 1. 将未审核改成未通过
     * 2. 请求方式: GET
     * 3. 必须参数: id, reason
     */
    public function refuseVerify()
    {
        $data = input('get.');
        filter_var($data,FILTER_SANITIZE_NUMBER_INT);
        $model = new ApplyopenModel();
        $isSuccess = $model->unPassVerify($data);
        if ($isSuccess){
            return 'YES';
        }else{
            $this->error('拒绝失败');
        }
    }

    /***
     * 1. 获取所有已审核
     * 2. 请求方式: POST
     * 3. 必须参数: type = 2表示已审核
     */
    public function getAllVerify(){
        $params = $this->request->param();
        $model = new ApplyopenModel();
        $list = $model->getVerifyList();
        $this->assign('type', 2);
        $this->assign('list', $list);
        $list->appends($params);
        $where['status'] = 1;
        $count = $model->getCount($where);
        $this->assign('count', $count);
        $this->assign('page', $list->render());

        return $this->fetch('unverify');
    }

    /***
     * 1. 获取所有未通过
     * 2. 请求方式: POST
     * 3. 必须参数: type = 3表示未通过
     */
    public function getAllUnPassVerify(){
        $model = new ApplyopenModel();
        $list = $model->getUnPassList();
        $this->assign('type', 3);
        $this->assign('list', $list);
        $params = $this->request->param();
        $list->appends($params);
        $where['status'] = 2;
        $count = $model->getCount($where);
        $this->assign('count', $count);
        $this->assign('page', $list->render());

        return $this->fetch('unverify');
    }





}